import 'package:flutter/material.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter_audit_app/routes/router_path.dart';
import 'package:flutter_audit_app/ui/home/routes/home_router.dart';
import 'package:flutter_audit_app/ui/login/login_page.dart';
import 'package:flutter_audit_app/ui/login/splash_page.dart';
import 'package:flutter_audit_app/ui/mine/routes/mine_router.dart';
import 'package:flutter_audit_app/ui/msg/routes/msg_router.dart';
import 'package:flutter_audit_app/ui/stat/routes/stat_router.dart';
import 'package:flutter_audit_app/widgets/nav_bar.dart';

import '404.dart';
import 'i_router.dart';

class Routes {


  static List<IRouterProvider> _listRouter = [];

  static final FluroRouter router = FluroRouter();

  static void initRoutes() {
    ///指定路由跳转错误返回页
    router.notFoundHandler = Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      debugPrint('未找到目标页');
      return NotFoundPage();
    });

    router.define(
      RouterPath.splash,
      handler: Handler(handlerFunc:
          (BuildContext context, Map<String, List<String>> params) {
        return SplashPage();
      }),
    );

    //登录页
    router.define(
      RouterPath.login,
      handler: Handler(handlerFunc:
          (BuildContext context, Map<String, List<String>> parmas) {
        return LoginPage();
      }),
    );

    //主页
    router.define(
      RouterPath.home,
      handler: Handler(handlerFunc:
          (BuildContext context, Map<String, List<String>> parmas) {
        return NavBarController();
      }),
    );

    _listRouter.clear();

    ///各自模块管理各自路由，统一在此添加初始化
    //主页路由组
    _listRouter.add(HomeRouter());
    //消息路由组
    _listRouter.add(MsgRouter());
    //统计路由组
    _listRouter.add(StatRouter());
    //我的路由组
    _listRouter.add(MineRouter());
    //登录注册路由组
    // _listRouter.add(UserRouter());

    ///初始化路由
    _listRouter.forEach((routerProvider) {
      routerProvider.initRouter(router);
    });
  }
}
